package com.xuecheng.content.controller;

import com.xuecheng.content.model.dto.CoursePreviewDTO;
import com.xuecheng.content.model.po.CoursePublish;
import com.xuecheng.content.service.ICoursePublishService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

/**
 * @author 勾新杰
 * @version 1.0
 * @description: 课程发布接口
 * @date 2025/2/14 17:27
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/course-publish")
@Api(tags = "课程发布接口")
public class CoursePublishController {

    /**
     * 课程发布service
     */
    private final ICoursePublishService coursePublishService;

    /**
     * 课程发布
     * @param courseId 课程id
     */
    @PostMapping("/publish/{courseId}")
    @PreAuthorize("hasAuthority('xc_teachmanager_course_publish')")
    @ApiOperation(value = "课程发布")
    public void coursePublish(@PathVariable("courseId") Long courseId){
        coursePublishService.publish(courseId);
    }

    /**
     * 课程下线
     * @param courseId 课程id
     */
    @GetMapping("/offline/{courseId}")
    @PreAuthorize("hasAuthority('xc_teachmanager_course_offline')")
    @ApiOperation(value = "课程下线")
    public void courseOffline(@PathVariable("courseId") Long courseId){
        coursePublishService.offline(courseId);
    }

    /**
     * 根据课程id获取课程发布信息
     * @param courseId 课程id
     * @return 课程发布信息
     */
    @GetMapping("/{courseId}")
    @ApiOperation("根据课程id获取课程发布信息")
    public CoursePublish getById(@PathVariable("courseId") Long courseId){
        return coursePublishService.getById(courseId);
    }
}
